//
//  FingerPrintViewController.swift
//  HHSwift
//
//  Created by 华宏 on 2020/9/8.
//  Copyright © 2020 huahong. All rights reserved.
//

import UIKit
import LocalAuthentication

class FingerPrintViewController: BaseViewController {

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        fingerPrint()
        
        
    }
    
    
    func fingerPrint() {
       
        let context = LAContext()
        
        //验证指纹识别是否可用
        let fingerPrintCanUse = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
        
        if fingerPrintCanUse == true {
            
            context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "请验证指纹") { (success, error:Error?) in
                
                if success == true {
                    print("指纹验证成功")
                }
                                
                
                if let error = error {
                /*
                   LAErrorAuthenticationFailed - 指纹无法识别
                   LAErrorUserCancel     --用户点击了取消
                   LAErrorUserFallback   --用户点击了输入密码
                   LAErrorSystemCancel   --系统取消
                   LAErrorPasscodeNotSet --因为你设备上没有设置密码
                   LAErrorTouchIDNotAvailable  --设备没有Touch ID
                   LAErrorTouchIDNotEnrolled   --因为你的用户没有输入指纹
                   LAErrorTouchIDLockout --多次输入，密码锁定
                   LAErrorAppCancel--    比如电话进入，用户不可控的
                   */
                       
                 print("指纹验证失败：",error)
                }
                
            }
            
        }else{
            print("指纹识别不可用")
        }
        
    }
    

}
